package com.ztesoft.huangfu.learning.springboot.springbootswagger2.controller;


import com.ztesoft.huangfu.learning.springboot.springbootswagger2.entity.Student;
import org.springframework.web.bind.annotation.*;


/**
 * 无参
 * http://10.45.28.65:8099/hfhello/V1/testApi
 * path参数
 * http://127.0.0.1:8099/hello/V1/testApiPathParam/123配置契约url中带上{paramname}
 * query参数
 * http://127.0.0.1:8099/hfhello/V1/testApiQueryParam?name=huangfu 契约url只配置方法,在参数名设置
 * body参数(post)
 * http://127.0.0.1:8099/hfhello/V1/testApiBodyParam 契约url只配置方法  在参数名设置
 * delete
 * http://127.0.0.1:8099/hfhello/V1/testApiDelete?id=zhangsan
 */
@RestController
public class TestController {


    @GetMapping("/getuser/{parm1}/{parm2}")
    public String getuser(@PathVariable("parm1") String parm1, @PathVariable("parm2") String parm2) {
        return "hello world！" + parm1 + ";from 8083 path param" + parm2;
    }


    @GetMapping("/testApi")
    public String testApi() {
        return "你好 ;from 8083 no param";
    }

    @GetMapping("/testApiPathParam/{id}")
    public String testApiPathParam(@PathVariable("id") String id) {
        return "hello world！" + id + ";from 8083 path param";
    }

    @GetMapping("/testApiQueryParam")
    public String testApiQueryParam(String name) {
        return "hello world！" + name + ";from 8083 query param";
    }


    @PostMapping("/testApiBodyParam")
    @ResponseBody
    public String testApiBodyParam(@RequestBody Student student) {
        System.out.println(student.getId() + "  " + student.getAge() + "  " + student.getName());
        return "hello world！" + student + ";from 8083 query param";
    }

    @DeleteMapping("/testApiDelete")
    public String testApiDelete(String id) {
        return "hello world！" + id + ";from 8083 delete param";
    }

    @PostMapping("/testApiHeader")
    public String testApiHeader(@RequestHeader String headParam) {
        return "hello world！" + headParam + ";from 8083 headParam";
    }
}
